﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using CarFrameWork.Common;
namespace CarFrameWork.Model
{
	/// <summary>
	/// 类RoleRight。
	/// </summary>
	[Serializable]
	public partial class RoleRight
	{
		public RoleRight()
		{}
		#region Model
		private int _rolerightid;
		private int? _roleid;
		private int? _moduleid;
		/// <summary>
		/// 
		/// </summary>
		public int RoleRightID
		{
			set{ _rolerightid=value;}
			get{return _rolerightid;}
		}
		/// <summary>
		/// 
		/// </summary>
		public int? RoleID
		{
			set{ _roleid=value;}
			get{return _roleid;}
		}
		/// <summary>
		/// 
		/// </summary>
		public int? ModuleID
		{
			set{ _moduleid=value;}
			get{return _moduleid;}
		}
		#endregion Model


		#region  Method

		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public RoleRight(int RoleRightID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select RoleRightID,RoleID,ModuleID ");
			strSql.Append(" FROM [RoleRight] ");
			strSql.Append(" where RoleRightID=@RoleRightID ");
			SqlParameter[] parameters = {
					new SqlParameter("@RoleRightID", SqlDbType.Int,4)};
			parameters[0].Value = RoleRightID;

			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["RoleRightID"]!=null && ds.Tables[0].Rows[0]["RoleRightID"].ToString()!="")
				{
					this.RoleRightID=int.Parse(ds.Tables[0].Rows[0]["RoleRightID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["RoleID"]!=null && ds.Tables[0].Rows[0]["RoleID"].ToString()!="")
				{
					this.RoleID=int.Parse(ds.Tables[0].Rows[0]["RoleID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ModuleID"]!=null && ds.Tables[0].Rows[0]["ModuleID"].ToString()!="")
				{
					this.ModuleID=int.Parse(ds.Tables[0].Rows[0]["ModuleID"].ToString());
				}
			}
		}

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{

		return DbHelperSQL.GetMaxID("RoleRightID", "RoleRight"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int RoleRightID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from [RoleRight]");
			strSql.Append(" where RoleRightID=@RoleRightID ");

			SqlParameter[] parameters = {
					new SqlParameter("@RoleRightID", SqlDbType.Int,4)};
			parameters[0].Value = RoleRightID;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into [RoleRight] (");
			strSql.Append("RoleID,ModuleID)");
			strSql.Append(" values (");
			strSql.Append("@RoleID,@ModuleID)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@RoleID", SqlDbType.Int,4),
					new SqlParameter("@ModuleID", SqlDbType.Int,4)};
			parameters[0].Value = RoleID;
			parameters[1].Value = ModuleID;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update()
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update [RoleRight] set ");
			strSql.Append("RoleID=@RoleID,");
			strSql.Append("ModuleID=@ModuleID");
			strSql.Append(" where RoleRightID=@RoleRightID ");
			SqlParameter[] parameters = {
					new SqlParameter("@RoleID", SqlDbType.Int,4),
					new SqlParameter("@ModuleID", SqlDbType.Int,4),
					new SqlParameter("@RoleRightID", SqlDbType.Int,4)};
			parameters[0].Value = RoleID;
			parameters[1].Value = ModuleID;
			parameters[2].Value = RoleRightID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int RoleRightID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from [RoleRight] ");
			strSql.Append(" where RoleRightID=@RoleRightID ");
			SqlParameter[] parameters = {
					new SqlParameter("@RoleRightID", SqlDbType.Int,4)};
			parameters[0].Value = RoleRightID;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public void GetModel(int RoleRightID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select RoleRightID,RoleID,ModuleID ");
			strSql.Append(" FROM [RoleRight] ");
			strSql.Append(" where RoleRightID=@RoleRightID ");
			SqlParameter[] parameters = {
					new SqlParameter("@RoleRightID", SqlDbType.Int,4)};
			parameters[0].Value = RoleRightID;

			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["RoleRightID"]!=null && ds.Tables[0].Rows[0]["RoleRightID"].ToString()!="")
				{
					this.RoleRightID=int.Parse(ds.Tables[0].Rows[0]["RoleRightID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["RoleID"]!=null && ds.Tables[0].Rows[0]["RoleID"].ToString()!="")
				{
					this.RoleID=int.Parse(ds.Tables[0].Rows[0]["RoleID"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ModuleID"]!=null && ds.Tables[0].Rows[0]["ModuleID"].ToString()!="")
				{
					this.ModuleID=int.Parse(ds.Tables[0].Rows[0]["ModuleID"].ToString());
				}
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select * ");
			strSql.Append(" FROM [RoleRight] ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		#endregion  Method
	}
}

